package com.feng.web.interceptor;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.io.File;

/**
 * Created by Administrator on 2017/4/23.
 */
public class SessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.println("sessionCreated:"+se.getSession().getId());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        if(session.getAttribute("totalBill")!=null){
            File file = new File(session.getAttribute("totalBill").toString());
            System.out.println("del:"+file.getAbsoluteFile());
            file.delete();
        }
        if(session.getAttribute("subBill")!=null){
            File file = new File(session.getAttribute("subBill").toString());
            System.out.println("del:"+file.getAbsoluteFile());
            file.delete();
        }
        System.out.println("sessionDestroyed:"+se.getSession().getId());
    }
}
